package com.huang.foundation.controller;

import com.huang.entity.result.HStringResult;
import com.huang.entity.result.ResultBuilder;
import com.huang.foundation.entity.request.SensitiveWordsCheckParam;
import com.huang.foundation.service.SensitiveWordsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author HuangShen
 * @Date 2022/3/1 08:14
 * @Describe
 */
@RestController
@RequestMapping("/public")
public class SensitiveWordsController {

    @Resource
    private SensitiveWordsService sensitiveWordsService;

    @GetMapping("/check/sensitive_words")
    public HStringResult<List<String>> sensitiveWordsCheck(@RequestBody SensitiveWordsCheckParam sensitiveWordsCheckParam){
        try {
            sensitiveWordsCheckParam.check();
            List<String> sensitiveWordsMatch = this.sensitiveWordsService.sensitiveWordsMatch(sensitiveWordsCheckParam.getText());
            return ResultBuilder.successHSingle(sensitiveWordsMatch);
        }catch (Exception e){
            return ResultBuilder.failHSingle(e.getMessage());
        }

    }



}
